<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserSelectTable extends LazyRenderable
{
    public function grid(): Grid
    {
        $is_limit = $this->is_limit??false;
        $table = $this->table??"";
        $id = $this->id??0;

        return Grid::make(new User(), function (Grid $grid) use ($is_limit,$table,$id) {
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableActions();
            if ($is_limit){
                $grid->model()->whereNotIn("id",function ($query) use ($table,$id) {
                    $query->from($table)->select(["user_id"])->where("id","<>",$id);
                });
            }else{
                $grid->model()->orderByDesc("id");
            }
            $grid->disableViewButton();
            $grid->disableQuickEditButton();
            $grid->model()->whereNotNull("nickname");
            $grid->column('id')->sortable();
            $grid->column('avatar','头像')->image('',50,50);
            $grid->column('nickname','昵称');
            $grid->column('created_at');
            $grid->quickSearch(['id','nickname']);
            $grid->paginate(8);
        });
    }


}
